//
//  MovieDetailView.m
//  豆瓣
//
//  Created by dllo on 15/12/9.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "MovieDetailView.h"
#import "UIImageView+WebCache.h"

@interface MovieDetailView ()

@property (nonatomic, retain) UIImageView *movieImageView;
@property (nonatomic, retain) UILabel *rating;
@property (nonatomic, retain) UILabel *date;
@property (nonatomic, retain) UILabel *runtime;
@property (nonatomic, retain) UILabel *genres;
@property (nonatomic, retain) UILabel *country;
//@property (nonatomic, retain) UILabel *maker;
@property (nonatomic, retain) UILabel *actors;
//@property (nonatomic, retain) UILabel *c;
@property (nonatomic, retain) UILabel *plot;
@property (nonatomic, retain) UILabel *rating_count;


@end

@implementation MovieDetailView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)dealloc{
    [_rating_count release];
    [_runtime release];
    [_genres release];
    [_country release];
    [_actors release];
    [_plot release];
    [_date release];
    [_rating release];
    [_movieImageView release];
    [super dealloc];
}

- (void)setMovie:(Movie *)movie{
    if (_movie != movie) {
        [_movie release];
        _movie = [movie retain];
    }
    NSLog(@"是否是主线程 === %d",[NSThread isMainThread]);
    //下面的方法是回到主线程
//    dispatch_async(dispatch_get_main_queue(), ^{
  
        
        self.rating.text = self.movie.rating;
        
    self.runtime.text = self.movie.runtime;
    
//    NSLog(@"_____%@_____", self.runtime.text);
    self.plot.text = self.movie.plot_simple;
    self.date.text = self.movie.release_date;
        [self.date sizeToFit];

    self.actors.text = self.movie.actors;
        self.actors.numberOfLines = 0;
        [self.actors sizeToFit];

    self.country.text = self.movie.country;
        [self.rating sizeToFit];
        
        self.rating_count.text = [self.movie.rating_count stringByAppendingString:@" 评论)"];
        [self.rating_count sizeToFit];
        
        self.genres.text = self.movie.genres;
        [self.genres sizeToFit];

        

    NSURL *url = [NSURL URLWithString:self.movie.poster];
//    NSData *data = [NSData dataWithContentsOfURL:url];
//
//    self.movieImageView.image = [UIImage imageWithData:data];
        [self.movieImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"picholder"]];
        
//    });
}

- (void)createSubviews{
    
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.frame];
    scrollView.backgroundColor = [UIColor whiteColor];
    scrollView.contentSize = CGSizeMake(375, 667 * 2);
    [self addSubview:scrollView];
    
    self.movieImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 120, 180)];
    self.movieImageView.backgroundColor = [UIColor blackColor];
    [scrollView addSubview:_movieImageView];
    [_movieImageView release];
    
    
    
    self.rating = [[UILabel alloc] initWithFrame:CGRectMake(210, 25, 50, 20)];
    self.rating.backgroundColor = [UIColor whiteColor];
    self.rating.text = @"评分: 7.1   (4925评论)";
    [scrollView addSubview:_rating];
    [_rating release];
    
        UILabel *rating1 = [[UILabel alloc]initWithFrame:CGRectMake(170, 25, 50, 20)];
        rating1.backgroundColor = [UIColor whiteColor];
        [scrollView addSubview:rating1];
        rating1.text = @"评分:";
        [rating1 sizeToFit];
        [rating1 release];
    //
    
    UILabel *rating_count1 = [[UILabel alloc] initWithFrame:CGRectMake(250, 25, 5, 20)];
    rating_count1.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:rating_count1];
    rating_count1.text = @"(";
    [rating_count1 sizeToFit];
    [rating_count1 release];
    
    self.rating_count = [[UILabel alloc] initWithFrame:CGRectMake(260, 25, 50, 20)];
    self.rating_count.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:_rating_count];
    [_rating_count release];
    
    
    self.date = [[UILabel alloc] initWithFrame:CGRectMake(170, 60, 100, 20)];
    //    UILabel *date = [[UILabel alloc]initWithFrame:CGRectMake(200, 85, 175, 25)];
    self.date.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:_date];
//    self.date.text = @"20140901";
    [_date release];
    
    self.runtime = [[UILabel alloc]initWithFrame:CGRectMake(170, 95, 100, 20)];
    self.runtime.backgroundColor = [UIColor whiteColor];
//    self.runtime.text = @"126 min";
//    [self.runtime sizeToFit];
    [scrollView addSubview:_runtime];
    [_runtime release];
    
    self.genres = [[UILabel alloc]initWithFrame:CGRectMake(170, 130, 100, 20)];
    self.genres.backgroundColor = [UIColor whiteColor];
//    self.genres.text = @"动作/冒险/惊悚";
    [scrollView addSubview:_genres];
    [_genres release];
    
    self.country = [[UILabel alloc]initWithFrame:CGRectMake(170, 165, 100, 20)];
    self.country.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:_country];
//    self.country.text =@"美国法国";
    [_country release];
    
    UILabel *b = [[UILabel alloc]initWithFrame:CGRectMake(30, 210, 100, 40)];
    b.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:b];
    b.text = @"制作人";
    b.font = [UIFont systemFontOfSize:22];
    b.font = [UIFont boldSystemFontOfSize:22];
    [b release];
    
    self.actors = [[UILabel alloc] initWithFrame:CGRectMake(30, 250, 330, 100)];
    self.actors.backgroundColor = [UIColor whiteColor];
//    self.actors.text = @"西尔维斯特·史泰龙 Sylvester Stallone,杰森·斯坦森 Jason Statham, 梅尔·吉布森 Mel Gibson,李连杰 Jet Li";
    [scrollView addSubview:_actors];
    [_actors release];
    
    
    UILabel *c = [[UILabel alloc]initWithFrame:CGRectMake(30, 335, 100, 40)];
    c.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:c];
    c.text = @"电影情节";
    c.font = [UIFont systemFontOfSize:22];
    c.font = [UIFont boldSystemFontOfSize:22];
    [c release];
    
    self.plot = [[UILabel alloc]initWithFrame:CGRectMake(30, 380, 340, 100)];
    self.plot.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:_plot];
    self.plot.text = @"  在此次第三步的故事中, 巴尼(史泰龙 饰) 与克里斯马斯 (杰森斯坦森 饰) 领衔的敢死队将面对迎战昔日战友、如今的军火枭雄康拉德·斯通班克斯 (梅尔·吉布森 饰)。斯通班克斯曾侥幸死里逃生过一次, 现在他对敢死队下达了绝杀令。巴尼则另有一番打算: 为迎战强敌, 巴尼决定给敢死队注入新鲜血液, 招募了更快更强的高科技战斗新生, 搭配长枪硬炮的硬汉前辈, 展开一番大决战";
    self.plot.numberOfLines = 0;
    [self.plot sizeToFit];
    
    [_plot release];
    
}


@end
